<?php

namespace app\admin\model;

use think\Model;
use think\model\concern\SoftDelete;

class Tickets extends Model
{
//    use SoftDelete;
//    protected $deleteTime = 'delete_time';

//    public function user(){
//        return $this->belongsTo('users','use_id','id');
//    }
    public function getExpireAttr($value){
        $expire = [
            '0'     =>  '永久',
            '1'     =>  '一天',
            '2'     =>  '一周',
            '3'     =>  '一月',
            '4'     =>  '一年'
        ];
        return $expire[$value];
    }
    public function getUseIdAttr($value){

        $use = $value > 0 ? (new Users())->field('team,nickname')->find($value) : 0;
        return $use;
    }
    public function doAdd($data)  {
        try{
            $str = str_replace("\r\n", "\n",trim($data['content']));
            $arr = array_filter(explode("\n",$str));
            $all = [];
            foreach ($arr as $k=>$v){
                $line = [];
                $line['content'] = $v;
                $line['type'] = AttrToCdkValue($data['type']);
                $line['use_id'] = 0;
                $line['expire'] = $data['expire'];
                $all[] =  $line;
            }
            $this->saveAll($all);
            return true;
        }catch (Exception $exception){
            return $exception->getMessage();
        }
    }
}